<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <!-- Bootstrap -->
    <title>订单列表</title>
    <!-- Bootstrap -->
    <link href="../js/bootstrap/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<table class="table table-bordered" id="orderTable">
  <thead>
    <tr>
        <th>订单编号</th>
        <th>金额</th>
        <th>商品个数</th>
        <th>创建时间</th>
        <th>支付时间</th>
        <th>订单状态</th>
        <th>收件人</th>
        <th>地址</th>
        <th>电话</th>
        <th>操作</th>
    </tr>
  </thead>
  <tbody>

  </tbody>
</table>
<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
<script src="../js/jquery-3.3.1.js"></script>
<script src="../js/jquery.cookie.min.js"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script type="text/javascript" src="../js/common/common.js"></script>
<script>
$(function () {
    initOrderTable();
})

function initOrderTable() {
    // 获取sessionStorage中的token
    let v_token = sessionStorage.getItem(config.X_TOKEN);
    if (v_token) {
        $.ajax({
            type:"get",
            url:config.SERVER_URL+"/orders/findOrderList",
            beforeSend:function (xhr) {
                xhr.setRequestHeader(config.X_AUTH, v_token);
            },
            success:function (res) {
                if (res.code == config.SUCCESS) {
                    console.log(res);
                    let v_orderList = res.data;
                    let v_html = "";
                    for (let v_order of v_orderList) {
                        let v_payTime = "暂时还未支付";
                        if (v_order.payTime) {
                            v_payTime = v_order.payTime;
                        }
                        let v_status;
                        if (v_order.status == 0) {
                            v_status = "未支付";
                        } else if (v_order.status == 10) {
                            v_status = "已支付";
                        } else if (v_order.status == 40) {
                            v_status = "交易关闭";
                        }
                        v_html += "<tr>";
                        v_html += "<td>"+v_order.id+"</td>";
                        v_html += "<td><span style='color:red;font-weight: bold'>¥"+v_order.totalPrice+"</span></td>";
                        v_html += "<td>"+v_order.totalCount+"</td>";
                        v_html += "<td>"+v_order.createTime+"</td>";
                        v_html += "<td>"+v_payTime+"</td>";
                        v_html += "<td>"+v_status+"</td>";
                        v_html += "<td>"+v_order.recipientName+"</td>";
                        v_html += "<td>"+v_order.addr+"</td>";
                        v_html += "<td>"+v_order.phone+"</td>";
                        v_html += '<td><a href="javascript:;" onclick="toPay(\''+v_order.id+'\');">支付</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:;">取消订单</a></td>';
                        v_html += "</tr>";
                    }
                    $("#orderTable tbody").html(v_html);
                }
            }
        })
    }
}

function toPay(v_id) {
    location.href = config.SERVER_URL+"/pay/aliPayPage?orderId="+v_id;
}
</script>
</body>
</html>